// screeps 代码入口
import CreepExtension = require('./mount.creep');
import creepConfigs = require('./creepConfigs');
import {
  spawnCreeps,
  clearCreepMemory,
  setTimer,
  calculateCreepNumber,
} from "./utils";
import {towerAction} from "./tower";

clearCreepMemory();
calculateCreepNumber();
spawnCreeps();
global.creepConfigMeta = creepConfigs()
module.exports.loop = function (): void {
  const main = Game.spawns['Spawn'].room;
  CreepExtension();
  setTimer(100, () => {
    global.creepConfigMeta = creepConfigs()
  });
  setTimer(60, calculateCreepNumber);
  setTimer(60, spawnCreeps);//每六十个tick,检查全局creep
  setTimer(() => main.energyAvailable === main.energyCapacityAvailable, spawnCreeps);//满能量全局监视
  towerAction();
  // 遍历所有 creep 并执行 work 方法
  for (const name in Game.creeps) {
    Game.creeps[name].work()
  }
};
